!expect true
; Change this statement to the appropriate flow control
; (for //e,//gs use HARDWARE, for //C use NONE)
!flow NONE
; Change this statement to the baud rate your machine defaults to
!goto try300
;-----------------------------------------------------------------
; Try 300 baud
:try300
'Trying 300 baud
!onerror try1200
!baud 300 
;This first line makes the apple echo input
~PR#2
]
!goto INIT
;
; Try 1200 baud
:try1200
'Trying 1200 baud
!onerror try2400
!baud 1200
~PR#2
]
!goto INIT
;
; Try 2400 baud
:try2400
'Trying 2400 baud
!onerror try9600
!baud 2400
~PR#2
]
!goto INIT
;
; Try 9600 baud
:try9600
'Trying 9600 baud
!onerror try19200
!baud 9600
~PR#2
]
!goto INIT
;
; Try 19200 baud
:try19200
'Trying 19200 baud
!onerror try115200
!baud 19200
~PR#2
]
!goto INIT
;
; Try 115.2k baud
:try115200
'Trying 115.2k baud
!onerror FAILURE
!baud 115200
~PR#2
]
; There's no need to call the 115.2 init code because we're already at that speed!
*home:call -151
goto END

:INIT
!onerror FAILURE
*home:call -151
;This binary code kicks the SSC into 115.2k baud, 8-N-1
*300:a9 10 8d ab c0 a9 0b 8d aa c0 ad a8 c0 60
;
;Start the program (note, this changes the baud rate so 
;~ is used so we don't require a prompt afterwards)
;
~300g
;Extra linefeed just in case!
~
!baud 115200
!wait 500
;Extra linefeed just in case!
~
;Expect a valid monitor prompt before going on!
*
"Now operating at 115.2k baud
!goto END

:FAILURE
!error "Could not figure out what baud rate the apple is using!  Make sure its port settings are No partity, 8 data bits and 1 stop bit (N-8-1)"

:END